/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ui.gui.actions;

import java.awt.event.ActionEvent;
import java.io.File;

import javax.swing.AbstractAction;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.filechooser.FileFilter;

import common.Commands;

import ui.WindowManager;
import ui.gui.documents.AbstractDocument;
import ui.gui.documents.EditorFactory;
import ui.gui.documents.toolbox.Workspace;

/**
 *
 * @author stephane
 */
public class SaveWorkspaceAction extends AbstractAction {
    private static final long serialVersionUID = 1L;

    public SaveWorkspaceAction(JFrame parent) {
        super("Save workspace", new javax.swing.ImageIcon(SaveWorkspaceAction.class.getResource("/resources/saveFile.png")));
        putValue(SHORT_DESCRIPTION, "Save workspace");
    }

    @Override
    public void actionPerformed(ActionEvent e) {
    	JFileChooser fileChooser = new JFileChooser();
        fileChooser.setFileFilter(new FileFilter() {
        	@Override
        	public boolean accept(File f) {
        		return f.isDirectory() || f.getName().endsWith(".clac");
        	}
        	@Override
        	public String getDescription() {
        		return "CLAC workspace (*.clac)";
        	}
        });
        fileChooser.showSaveDialog(null);
        File file = fileChooser.getSelectedFile();
        if (file !=null && file.isFile())
        {
            Commands.RunCommand("save-workspace " + file.getAbsolutePath(), true);
        }
	
    }
}